package marks;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class marksReducer extends Reducer<Text, IntWritable,Text, DoubleWritable> {

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, DoubleWritable>.Context context) throws IOException, InterruptedException {
        double total=0;
        int count=0;
        for (IntWritable v:values)
        {
            total= total+v.get();
            count++;
        }

        double aver = total/count;

        context.write(key,new DoubleWritable(aver));


    }
}
